package cs271.examples.binarytrees;

public class BinaryTreeUtil {
	public static int countNumberOfNodes(BinaryTreeElement e) {
		if(e==null) {
            //base case:
            return 0;
        } else {
            return 1 + countNumberOfNodes(e.getLeft()) + 
                    countNumberOfNodes(e.getRight());
        } 
	}
	
	public static int heightOfTree(BinaryTreeElement e) {
        if(e == null || (e.getLeft() == null && e.getRight()==null)) {
            return 0;
        } else {
            return 1 + Math.max(heightOfTree(e.getLeft()), heightOfTree(e.getRight()));
        }
	}
	
	public static void preOrderTraversal(BinaryTreeElement e) {
		if(e!=null) {
			preOrderTraversal(e.getLeft());
			System.out.println(e.element);
			preOrderTraversal(e.getRight());
		}
	}
}
